package phone.qyg.com.qyg.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.app.application.QXApplication;
import com.app.utils.CommonUtil;

import phone.qyg.com.qyg.R;
import phone.qyg.com.qyg.model.Delete;


/**
 * 作者：lblbh on 2017/5/27 13:40
 * 邮箱：lanbuhan@163.com
 * 功能：同意删除处理
 */
public class PopuDelete {

    //R.layout.popu_delete
    public static void showPopuWinDeleteCourse(View v, Delete delete, int layout, final int position, final DeleteState state){

        LayoutInflater inflater = (LayoutInflater) QXApplication.getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View inflate = inflater.inflate(layout, null);
        final PopupWindow popupWindow = new PopupWindow(inflate, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);

        popupWindow.showAtLocation(v, 0, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.update();


        TextView title = (TextView) inflate.findViewById(R.id.delete_title_text);
        TextView content = (TextView) inflate.findViewById(R.id.delete_content_text);
        TextView delete_quit = (TextView) inflate.findViewById(R.id.delete_quit);
        TextView delete_sure = (TextView) inflate.findViewById(R.id.delete_sure);

        if(null != delete){
            title.setText(delete.title);
            delete_quit.setText(delete.quit);
            delete_sure.setText(delete.sure);

            String contentStr = delete.content;

            if(CommonUtil.isRequestStr(contentStr)){
                content.setText(CommonUtil.setAttributeText(delete.content));
            }else{
                content.setVisibility(View.GONE);
            }
        }


        delete_quit.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if(popupWindow.isShowing()){
                    popupWindow.dismiss();
                }
                if(state!= null)
                    state.state(false,position);
            }
        });

        delete_sure.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if(popupWindow.isShowing()){
                    popupWindow.dismiss();
                }
                if(state!= null)
                    state.state(true,position);
            }
        });


        inflate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(popupWindow.isShowing()){
                    popupWindow.dismiss();
                }
                if(state!= null)
                    state.state(false,position);
            }
        });

    }


    public interface DeleteState{
        public void state(boolean isSucess, int position);
    }
}
